package com.gljx.web.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gljx.web.Entity.ExerciseCarPlan;
import com.gljx.web.dao.CommonDao;
import com.gljx.web.dao.ExerciseCarPlanMapper;
import com.gljx.web.service.ExerciseCarPlanService;

@Service
@Transactional
public class ExerciseCarPlanServiceImpl extends CommonDao implements ExerciseCarPlanService{

	@Autowired
	private ExerciseCarPlanMapper exerciseCarPlanMapper;
	
	/**
	 *取分页数据    dmz 20160921
	 *@param pindex 页码
	 *@param psql SQL语句，需要带 rownum rn 例如：select rownum rn,t.* from zzda t
	 *@param psize 每页记录数
	 * */
	@Override
	public Map<String, Object> selectPage(int pindex, String psql, int psize) {
		  Map<String, Object> paramMap = new HashMap<String, Object>();
	       paramMap.put("Pindex", pindex);
	       paramMap.put("Psql", psql);
	       paramMap.put("Psize", psize);
	       paramMap.put("Pcount", oracle.jdbc.OracleTypes.INTEGER);
	       paramMap.put("v_cur", oracle.jdbc.OracleTypes.CURSOR);
	       this.getSqlSession().select("com.gljx.web.dao.ExerciseCarPlanMapper.pagemap", paramMap, null);
	       return  paramMap;
	}

	/**
	 * 取记录总数      dmz 20160921
	 * @param psql   SQL语句
	 * @param Pcount 记录总数
	 * @return
	 */
	@Override
	public Map<String, Object> selectPageCount(String psql) {
		   Map<String, Object> paramMap = new HashMap<String, Object>();
	       paramMap.put("Psql", psql);
	       paramMap.put("Pcount", oracle.jdbc.OracleTypes.INTEGER);
	       this.getSqlSession().select("com.gljx.web.dao.ExerciseCarPlanMapper.pagecount", paramMap, null);
	       return paramMap;
	}

	/**
	 * 根据条件查询
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<ExerciseCarPlan> selectExerciseCarPlan(String companyId, String fid, String fnameL2) {
		// TODO Auto-generated method stub
		 Map<String, Object> paramMap = new HashMap<String, Object>();
	     paramMap.put("v_companyId", companyId);
	     paramMap.put("v_fid", fid);
	     paramMap.put("v_fnameL2", fnameL2);
	     paramMap.put("v_cursor", oracle.jdbc.OracleTypes.CURSOR);
	     this.getSqlSession().select("com.gljx.web.dao.ExerciseCarPlanMapper.selectExerciseCarPlan", paramMap, null);
		 return (List<ExerciseCarPlan>) paramMap.get("v_cursor");
	}

	/**
	 * 实现获取上一个编码
	 */
	@Override
	public String selectFnumber(String companyId) {
		// TODO Auto-generated method stub
		return exerciseCarPlanMapper.selectFnumber(companyId);
	}

	/**
	 * 实现添加
	 */
	@Override
	public void addExerciseCarPlan(ExerciseCarPlan exerciseCarPlan) {
		// TODO Auto-generated method stub
		exerciseCarPlanMapper.insertSelective(exerciseCarPlan);
	}

	/**
	 * 实现根据fid删除
	 */
	@Override
	public void deleteExerciseCarPlanByFid(String fid) {
		// TODO Auto-generated method stub
		exerciseCarPlanMapper.deleteByPrimaryKey(fid);
	}

	/**
	 * 实现根据fid修改
	 */
	@Override
	public void modifyExerciseCarPlanByFid(ExerciseCarPlan exerciseCarPlan) {
		// TODO Auto-generated method stub
		exerciseCarPlanMapper.updateByPrimaryKeySelective(exerciseCarPlan);
	}

	@Override
	public List<ExerciseCarPlan> selectExerciseCarPlanExcel(String fnameL2, String fcompanyid) {
		Map<String, String> map = new HashMap<>();
		map.put("fnameL2",fnameL2);
		map.put("cfficompanyid",fcompanyid);
		return exerciseCarPlanMapper.selectExerciseCarPlanExcel(map);
	}


	//查询ExerciseCar表的fid
	@Override
	public String selExerciseCarPlanByFnumer(String fnumber, String fcompanyid) {

		return exerciseCarPlanMapper.selectByfunmber(fnumber,fcompanyid);
	}
}
